package com.example.sunmiv1.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.adapter.IndexPageAdapter;
import com.example.sunmiv1.entity.IndexPageBean;
import com.example.sunmiv1.utils.net.ACache;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FlowManageActivity extends Activity {

    @BindView(R.id.title_back)
    ImageView titleBack;
    @BindView(R.id.title_title)
    TextView titleTitle;
    @BindView(R.id.flowManage_gridView)
    GridView flowManageGridView;

    private Context context;
    private Intent intent;
    private ACache aCache;
    private IndexPageAdapter indexPageAdapter;
    private List<IndexPageBean> indexList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_flow_manage);
        ButterKnife.bind(this);
        context = this;
        aCache = ACache.get(context);
        titleTitle.setText(R.string.flowManageTitle);
        initListener();
    }

    private void initListener() {
        if("2".equals(aCache.getAsString("userType"))){
            indexList.add(new IndexPageBean(R.mipmap.good_warehousing, R.string.flowManage_warehousing));//入庫
            indexList.add(new IndexPageBean(R.mipmap.index_deposit, R.string.flowManage_outOfStock));//出庫單
        }else {
            indexList.add(new IndexPageBean(R.mipmap.good_warehousing, R.string.flowManage_store_allocation));//門店調撥表
            indexList.add(new IndexPageBean(R.mipmap.index_deposit, R.string.flowManage_outOfStock));//出庫單
        }

        indexPageAdapter = new IndexPageAdapter(context, indexList);
        flowManageGridView.setAdapter(indexPageAdapter);
        flowManageGridView.setOnItemClickListener((parent, view, position, id) -> {
            switch (indexList.get(position).getImg()) {
                case R.mipmap.good_warehousing:
                    if ("2".equals(aCache.getAsString("userType"))) {//店長
                        intent = new Intent(context, GoodWarehousingActivity.class); // 入庫單
                        startActivity(intent);
                    } else {
                        intent = new Intent(context, AllocationTubeListActvity.class);// 調撥單
                        startActivity(intent);
                    }
                    break;
                case R.mipmap.index_deposit:
                    intent = new Intent(context, StoreAllocationActivity.class);//出庫單
                    startActivity(intent);
                    break;
            }
        });
    }

    @OnClick(R.id.title_back)
    public void  onViewClicked() {
        finish();
    }
}
